/* Driller, a data extraction program
 * Copyright (C) 2005-2006 John Millikin
 *
 * file_errors.cpp
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "file_errors.h"
#include <errno.h>

namespace Errors {

FileError::FileError(const std::string& _file, const int _error_code) throw ():
  file(_file), error_code((_error_code < 0)? errno : _error_code){
}

std::string FileError::error_message() const throw(){
  std::string message = "Generic file error for " + file;

  if (error_code > 0)
    message += ": " + std::string(strerror(error_code));
  return message;
}

FileReadError::FileReadError(const std::string& _file, const int _error_code)
  throw(): FileError(_file, _error_code){}

std::string FileReadError::error_message() const throw(){
  std::string message =  "Error reading " + file;

  if (error_code > 0)
    message += ": " + std::string(strerror(error_code));
  return message;
}

FileWriteError::FileWriteError(const std::string& _file, const int _error_code)
  throw(): FileError(_file, _error_code){}

std::string FileWriteError::error_message() const throw(){
  std::string message = "Error writing " + file;

  if (error_code > 0)
    message += ": " + std::string(strerror(error_code));
  return message;
}

} // namespace
